
// <copyright file="AbstractDataReader.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The abstract data reader.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Data.Common
{
    using System;
    using System.Data;

    /// <summary>
    /// The abstract data reader.
    /// </summary>
    public abstract class AbstractDataReader : AbstractDataRecord, IDataReader
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the depth.
        /// </summary>
        public virtual int Depth { get; protected set; }

        /// <summary>
        /// Gets a value indicating whether is closed.
        /// </summary>
        public virtual bool IsClosed
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        /// Gets or sets the records affected.
        /// </summary>
        public virtual int RecordsAffected { get; protected set; }

        /// <summary>
        /// Gets the records read so far.
        /// </summary>
        public long RecordsReadSoFar { get; private set; }

        #endregion Public Properties

        #region Public Methods and Operators

        /// <summary>
        /// The close.
        /// </summary>
        public virtual void Close()
        {
            this.Dispose();
        }

        /// <summary>
        /// The dispose.
        /// </summary>
        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// The get data.
        /// </summary>
        /// <param name="i">
        /// The i.
        /// </param>
        /// <returns>
        /// The <see cref="IDataReader"/>.
        /// </returns>
        public override IDataReader GetData(int i)
        {
            return this;
        }

        /// <summary>
        /// The get schema table.
        /// </summary>
        /// <returns>
        /// The <see cref="DataTable"/>.
        /// </returns>
        public virtual DataTable GetSchemaTable()
        {
            return null;
        }

        /// <summary>
        /// The next result.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public virtual bool NextResult()
        {
            return true;
        }

        /// <summary>
        /// The read.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool Read()
        {
            bool couldRead = this.readProtected();
            if (couldRead)
            {
                this.RecordsReadSoFar++;
            }

            return couldRead;
        }

        #endregion Public Methods and Operators

        #region Methods

        /// <summary>
        /// The dispose.
        /// </summary>
        /// <param name="disposing">
        /// The disposing.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
        }

        /// <summary>
        /// The read protected.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected abstract bool readProtected();

        #endregion Methods
    }
}